package com.spring.transaction.service.impl;

import com.spring.transaction.po.SpringUser;
import com.spring.transaction.service.SpringUserService;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * @ClassName SpringUserServiceImpl
 * @Description
 * @Author suncx
 * @Date 2020/9/21 15:24
 * @Version 1.0
 */
public class SpringUserServiceImpl implements SpringUserService {
    private JdbcTemplate jdbcTemplate;

    public void setDataSource(DataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }
    public void save(SpringUser user) throws Exception {
        jdbcTemplate.update("insert into spring_user(name, age) values (?,?)", user.getName(), user.getAge());
        // 测试事务
        throw new Exception("AAA");
    }
}
